package com.compiler.logger;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

public class Logger {
	private Map<String, HashMap<String, Vector<String>>> logs = new HashMap<String, HashMap<String,Vector<String>>>();
	public final static String INFOLevel="INFO";
	public final static String ERRORLevel="ERROR";
	public final static String WARNINGLevel="WARNING";
	public String analizer;
	
	private HashMap<String, Vector<String>> getLevels() {
		HashMap<String, Vector<String>> level = new HashMap<String, Vector<String>>();
		level.put(INFOLevel, new Vector<String>());
		level.put(ERRORLevel, new Vector<String>());
		level.put(WARNINGLevel, new Vector<String>());
		return level;
	}
	
	public static class LoggerHolder {
		private static final Logger INSTANCE = new Logger();
	}
	
	public static Logger getInstance() {
		return LoggerHolder.INSTANCE;
	}
	
	public void log(String className, String level, String log, String analizer) {
		HashMap<String, Vector<String>> l = null;
		if(!logs.containsKey(className))
			l = this.getLevels();
		else l = logs.get(className);
		l.get(level).add(log);
		logs.put(className, l);
		this.analizer = analizer;
	}
	
	public Vector<String> getMessages(String className, String level) {
		return this.logs.get(className).get(level);
	}

	public String toString() {
		String ret = "################## Mensajes ##################\n";
		//for(String className : this.logs.keySet())
			int x=0;
			for(HashMap<String, Vector<String>> log : this.logs.values()){
				for(String level : log.keySet()) {
					for(String message : log.get(level))
						ret += "["+level+" "+logs.keySet().toArray()[x]+"]"+" "+message+"\n";
				}
				x++;
			}
		return ret;
	}
}
